/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
    public:
        bool isUnivalTree(TreeNode* root) {
            return dfs(root,root->val);
        }
        bool dfs(TreeNode* root , int val){
            if(root == nullptr) return true;
            
            if(root->val != val) return false;
            return dfs(root->left,val)&&dfs(root->right,val);
        }
    
        //dfs任务：检验二叉树是否为单值二叉树
        //逻辑：先检查节点是否为单值，如果是-》继续检查左子树和右子树，如果不是-》return false
    };